<?php
/**
 * Description of articles groups
 *
 * @author:	qfox
 * @package:	radiance
 * @copyright:	(c) 2011, alex <qfox@ya.ru> yaroshevich aka alex_ez. All rights reserved
 * @created:	11.05.2011, 14:34
 */
class articles_groups_admin_controller extends refbook_controller {

	protected $entity_title = 'articles group';
	protected $entities_title = 'articles groups';
	protected $captions = null;
	protected $item_title_key = 'title';

	// form and filter
	protected $pager_per_pages = '20,50,200,500';

	protected $order = 'id-';

	protected $url_patterns = array(
		'index' => '/admin/articles/groups/',
		'show' => '/admin/articles/groups/id:id/',
		'add' => '/admin/articles/groups/add/',
		'edit' => '/admin/articles/groups/edit/?id=:id',
		);

	public function on_call( &$walker ) {
		if (!$this->conf['enabled'])
			respi()->notfound();
	}

	public function on_initialize( &$walker ) {
		$this->conf = $this->config->articles;
		$this->conf['enabled'] = isset($this->conf['enabled']) && $this->conf['enabled'];
		if (!$this->conf['enabled'])
			return;

		$this->model = new articles_groups();

		$this->aa = self::instance_of('articles_admin');
		$this->aa->init_lists();

		$this->columns = array(
			'id' => array(
				'text' => __('ID'),
				'width' => '30px',
				'order' => true,
				),
			'title' => array(
				'text' => __('Title'),
				'order' => true,
				),
			'title0' => array(
				'text' => __('Title') . '. ' . __('Prepositional case'),
				'order' => true,
				),
			'articles' => array(
				'text' => __('Articles quantity'),
				'order' => '(select count(`id`) as `articles` from core_articles where `group_id` = `core_articles_groups`.`id`)+,`id`-',
				'value' => '(select count(`id`) as `articles` from core_articles where `group_id` = `core_articles_groups`.`id`)',
				),
			);

		$this->captions = array(
			'title'		=> __('Groups'),
			'index'		=> __('Articles groups'),

			'show'		=> __('Show group'),
			'add'		=> __('Create group'),
			'edit'		=> __('Modify group'),
			'remove'	=> __('Delete group'),

			'showing'	=> __('Group "%s"'),
			'adding'	=> __('New group'),
			'editing'	=> __('Modifing group "%s"'),
			'removing'	=> __('Deleting group "%s"'),
			);

		$this->fieldsets['index#filter'] = array(
			'id' => array( 'label' => __('ID'), 'type' => 'text', 'class' => 'shorttext' ),
			'title' => array( 'label' => __('Title'), 'type' => 'text' ),
			);

		if (!$walker->selfonly)
			parent::on_initialize( $walker );
	}

	protected function init_crumbs() {
		$this->crumbs['/admin/articles/'] = __('Articles');
		parent::init_crumbs();
	}

	protected function init_lists() {
		$r = parent::init_lists();
		$this->lists += $this->aa->get_lists();
		return $r;
	}
}


